function isNumeric(input){
    var RE = /^-{0,1}\d*\.{0,1}\d+$/;
    return (RE.test(input));
}

function disabledEnter(obj){
	$(obj).bind("keypress", function(e) {
		  if (e.keyCode == 13) return false;
	});
}

function readonlyAttr(obj){
	$(obj).attr("readonly","true"); 
}



function initSectionDropDown(dropDownSectionId,departmentId,sectionId)
{
	dropDownSectionId=$('#'+dropDownSectionId);
	dropDownSectionId.find('option').remove();
	
	$('<option />').val('').text('All Section').appendTo(dropDownSectionId);
	for(var i=0;i<globalSections.length;i++)
	{
		var tmpValue = globalSections[i].sectionId;
		var tmpText = globalSections[i].sectionName;
		
		if(globalSections[i].department==null) continue;
		
		if(globalSections[i].department.departmentId==departmentId)
			$('<option />').val(tmpValue).text(tmpText).appendTo(dropDownSectionId);


		//alert(i);			
	}

	if(sectionId!=undefined)
		dropDownSectionId.val(sectionId);
}

function initRoleCheckbox(divRoleId,sectionId,rolexId)
{
	divRoleId=$('#'+divRoleId);
	divRoleId.html('');
	
	for(var i=0;i<globalRoles.length;i++)
	{
		var tmpValue = globalRoles[i].systemRoleId;
		var tmpText = globalRoles[i].roleName;
		if(globalRoles[i].section==null) continue;
		if(globalRoles[i].section.sectionId==sectionId)
			$('<input type="checkbox" name="systemRoles['+i+'].systemRoleId" />').val(tmpValue).add('<span>'+tmpText+'</span><br>').appendTo(divRoleId);

	}

	
	if(rolexId!=undefined)
	{

		
		for(var i=0;i<rolexId.length;i++)
		{
			
			$('input[type="checkbox"]').each(function()
					{
				
				if($(this).val()==rolexId[i])
					$(this).attr('checked','checked');
					});

		}
		//divRoleId.val(sectionId);
	}
}

function moveElements(fromSelect,toSelect)
{
	var to_remove_counter=0; //number of options that were removed (num selected options)

	fromSelect = fromSelect.get(0);
	toSelect = toSelect.get(0);
	//move selected options to right select box (to)
	for (var i=0;i<fromSelect.options.length;i++)
	{
		if (fromSelect.options[i].selected==true)
		{
			var addtext=fromSelect.options[i].text;
			var addvalue=fromSelect.options[i].value;
			toSelect.options[toSelect.options.length]=new Option(addtext,addvalue);
			fromSelect.options[i].selected=false;
			++to_remove_counter;
		}
		else
		{
			fromSelect.options[i-to_remove_counter].selected=false;
			fromSelect.options[i-to_remove_counter].text=fromSelect.options[i].text;
			fromSelect.options[i-to_remove_counter].value=fromSelect.options[i].value;
		}
	}

	//now cleanup the last remaining options 
	var numToLeave=fromSelect.options.length-to_remove_counter;
	for (i=fromSelect.options.length-1;i>=numToLeave;i--) 
	{ 
		fromSelect.options[i]=null;
	}
}